
"""
589. N 叉树的前序遍历
"""

class Solution:

    def __init__(self):
        self.list1 = []

    def preorder(self, root: Node) -> List[int]:
        self.traverse(root)
        return self.list1

    '''遍历n叉树'''
    def traverse(self, root: Node):
        if not root:
            return
        # 前序位置
        self.list1.append(root.val)
        for child in root.children:
            self.traverse(child)
        # 后序位置
        self.list1.append(root.val)
